/*
 * Copyright (c) 2024 Hunan OpenValley Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "fs_manager/fs_manager.h"
#include <gtest/gtest.h>
#include "init_utils.h"
#include <cstring>
#include <cerrno>
#include <cstdlib>
#include <cstdio>
#include <sys/mount.h>

using namespace std;
using namespace testing::ext;
namespace init_ut {
struct Item {
    const char *mountPoint;
    const char *fsType;
};
class OtaDataRemountUnitTest : public testing::Test {
public:
    static void SetUpTestCase(void)
    {
        cout << "OTA Data Remount Unittest Begin!" << endl;
    };
    static void TearDownTestCase(void)
    {
        cout << "OTA Data Remount Unittest End!" << endl;
    };
    void SetUp(void) {};
    void TearDown(void) {};
};
HWTEST_F(OtaDataRemountUnitTest, Init_OtaDataRemount_001, TestSize.Level0)
{
    Item item = {"/data", "f2fs"};
    const char *options = "checkpoint=disable";
    int result = mount(item.mountPoint, item.mountPoint, item.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result, 0);

    Item item1 = {"/data", "ext4"};
    int result1 = mount(item1.mountPoint, item1.mountPoint, item1.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result1, 0);

    Item item2 = {"/data", "unknown_fs"};
    int result2 = mount(item2.mountPoint, item2.mountPoint, item2.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result2, 0);
}

HWTEST_F(OtaDataRemountUnitTest, Init_OtaDataRemount_002, TestSize.Level0)
{
    Item item = {"/data", "f2fs"};
    const char *options = "checkpoint=enable";
    int result = mount(item.mountPoint, item.mountPoint, item.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result, 0);

    Item item1 = {"/data", "ext4"};
    int result1 = mount(item1.mountPoint, item1.mountPoint, item1.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result1, 0);

    Item item2 = {"/data", "unknown_fs"};
    int result2 = mount(item2.mountPoint, item2.mountPoint, item2.fsType, MS_REMOUNT, options);
    EXPECT_EQ(result2, 0);
}

}